#include "debugthread.h"

DebugThread::DebugThread(SlideGenerator& generator){
    m_gen = &generator;
    connect(this, SIGNAL(genMsg()),m_gen,SLOT(GenerateSlide()));
    connect(this, SIGNAL(dbMsg(const char*)),m_gen,SLOT(FetchNewRoute(const char*)));
    connect(this, SIGNAL(slideMsg(const char*)), m_gen, SLOT(LoadNewTemplate(const char*)));
    connect(this, SIGNAL(newStopPositionMsg(int)),m_gen,SLOT(SelectFocalStop(int)));
}

void DebugThread::run(){

    std::cout   << "Command Summary\n"
                << "gn : Generate Slide\n"
                << "sl [FILE PATH] : Cache a new slide\n"
                << "st [STOP POSITION] : Set position of current Stop\n"
                << "db [ROUTE ID] : Load a new route into memory\n";

    char inputBuff[100];
    newStopPositionMsg(1);

    while (true){        

        //genMsg();
        memset(inputBuff,'\0',100);

        std::cin.getline(inputBuff, 100);


        std::string string = std::string(inputBuff).substr(0, std::string(inputBuff).find_first_of('\0', 0));

        if (string.substr(0,2) == "gn")
            genMsg();
        else if (string.substr(0,3) == "sl "){
            const char* temp = string.substr(3, string.size() - 2).c_str();
            slideMsg(temp);
        }
        else if (string.substr(0,3) == "st "){
            int temp = atoi(string.substr(3, string.size() - 2).c_str());
            newStopPositionMsg(temp);
        }
        else if (string.substr(0,3) == "db "){
            const char* temp = string.substr(3, string.size() - 2).c_str();
            dbMsg(temp);
        }
        else std::cout << "\aInvalid Command\n";

    }

}
